import React, { useRef, useState,useEffect } from 'react'

const usePri = (state)=>{
    console.log('usePri',state)
    const ref = useRef()
    useEffect(() => {
        console.log('usePri useEffect')
        ref.current=state
    })
    console.log(ref.current,'ref.current')
    return ref.current
}

const User = ()=>{
    console.log('hello')
    const [count,setCount] = useState(0)
    const prive = usePri(count)
    return (<p>
        <button onClick={()=>{
            setCount(count+1)
        }}>+</button>
         <button onClick={()=>{
            setCount(count-1)
        }}>-</button>
        <p>now : {count}</p>
         <p>pre : {prive}</p>
    </p>)
}

export default User